import BaseRouter from './base-history'
export default class HistoryRouter extends BaseRouter {
  constructor($router) {
    super($router)
    window.addEventListener('popstate', () => {
      this.$router.data.current = this.getPath()
    })
  }

  getPath() {
    const path = window.location.pathname
    return path || '/'
  }

  push(hash) {
    history.pushState(null, null, hash)
    this.$router.data.current = hash;
  }

  replace(path) {
    history.replaceState(null, null, path)
  }

  go(n) {
    window.history.go(n)
  }
}
